assert_that(p.cargo_process("generate-lockfile"),
execs().with_status(0));
- let lockfile = p.root().join("Cargo.lock");
let toml = p.root().join("Cargo.toml");
- let mut lock1 = String::new();
- File::open(&lockfile).unwrap().read_to_string(&mut lock1).unwrap();
+ let lock1 = p.read_lockfile();
// add a dep
File::create(&toml).unwrap().write_all(br#"
"#).unwrap();
assert_that(p.cargo("generate-lockfile"),
execs().with_status(0));
- let mut lock2 = String::new();
- File::open(&lockfile).unwrap().read_to_string(&mut lock2).unwrap();
+ let lock2 = p.read_lockfile();
assert!(lock1 != lock2);
// change the dep
"#).unwrap();
assert_that(p.cargo("generate-lockfile"),
execs().with_status(0));
- let mut lock3 = String::new();
- File::open(&lockfile).unwrap().read_to_string(&mut lock3).unwrap();
+ let lock3 = p.read_lockfile();
assert!(lock1 != lock3);
assert!(lock2 != lock3);
"#).unwrap();
assert_that(p.cargo("generate-lockfile"),
execs().with_status(0));
- let mut lock4 = String::new();
- File::open(&lockfile).unwrap().read_to_string(&mut lock4).unwrap();
+ let lock4 = p.read_lockfile();
assert_eq!(lock1, lock4);
}
foo = "bar"
"#;
let lockfile = p.root().join("Cargo.lock");
- {
- let mut lock = String::new();
- File::open(&lockfile).unwrap().read_to_string(&mut lock).unwrap();
- let data = lock + metadata;
- File::create(&lockfile).unwrap().write_all(data.as_bytes()).unwrap();
- }
+ let lock = p.read_lockfile();
+ let data = lock + metadata;
+ File::create(&lockfile).unwrap().write_all(data.as_bytes()).unwrap();
// Build and make sure the metadata is still there
assert_that(p.cargo("build"),
execs().with_status(0));
- let mut lock = String::new();
- File::open(&lockfile).unwrap().read_to_string(&mut lock).unwrap();
+ let lock = p.read_lockfile();
assert!(lock.contains(metadata.trim()), "{}", lock);
// Update and make sure the metadata is still there
assert_that(p.cargo("update"),
execs().with_status(0));
- let mut lock = String::new();
- File::open(&lockfile).unwrap().read_to_string(&mut lock).unwrap();
+ let lock = p.read_lockfile();
assert!(lock.contains(metadata.trim()), "{}", lock);
}
assert_that(p.cargo("generate-lockfile"),
execs().with_status(0));
- let mut lock0 = String::new();
- {
- File::open(&lockfile).unwrap().read_to_string(&mut lock0).unwrap();
- }
+ let lock0 = p.read_lockfile();
assert!(lock0.starts_with("[root]\n"));
assert_that(p.cargo("generate-lockfile"),
execs().with_status(0));
- let mut lock2 = String::new();
- {
- File::open(&lockfile).unwrap().read_to_string(&mut lock2).unwrap();
- }
+ let lock2 = p.read_lockfile();
assert!(lock2.starts_with("[root]\r\n"));
assert_eq!(lock1, lock2);
extern crate cargotest;
extern crate hamcrest;
-use std::fs::File;
-use std::io::prelude::*;
-
use cargotest::support::git;
use cargotest::support::registry::Package;
use cargotest::support::{execs, project, lines_match};
fn oldest_lockfile_still_works() {
Package::new("foo", "0.1.0").publish();
- let p = project("bar")
- .file("Cargo.toml", r#"
- [project]
- name = "bar"
- version = "0.0.1"
- authors = []
-
- [dependencies]
- foo = "0.1.0"
- "#)
- .file("src/lib.rs", "");
- p.build();
-
let lockfile = r#"
[root]
name = "bar"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
"#;
- File::create(p.root().join("Cargo.lock")).unwrap()
- .write_all(lockfile.as_bytes()).unwrap();
+
+ let p = project("bar")
+ .file("Cargo.toml", r#"
+ [project]
+ name = "bar"
+ version = "0.0.1"
+ authors = []
+
+ [dependencies]
+ foo = "0.1.0"
+ "#)
+ .file("src/lib.rs", "")
+ .file("Cargo.lock", lockfile);
+ p.build();
assert_that(p.cargo("build"),
execs().with_status(0));
- let mut lock = String::new();
- File::open(p.root().join("Cargo.lock")).unwrap()
- .read_to_string(&mut lock).unwrap();
+ let lock = p.read_lockfile();
assert!(lock.starts_with(lockfile.trim()));
}
[dependencies]
foo = "0.1.0"
"#)
- .file("src/lib.rs", "");
- p.build();
-
- File::create(p.root().join("Cargo.lock")).unwrap().write_all(br#"
+ .file("src/lib.rs", "")
+ .file("Cargo.lock", r#"
[root]
name = "bar"
version = "0.0.1"
[metadata]
"checksum baz 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "checksum"
"checksum foo 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "checksum"
-"#).unwrap();
+"#);
+
+ p.build();
assert_that(p.cargo("build"),
execs().with_status(0));
- let mut lock = String::new();
- File::open(p.root().join("Cargo.lock")).unwrap()
- .read_to_string(&mut lock).unwrap();
+ let lock = p.read_lockfile();
assert!(lock.starts_with(r#"
[root]
name = "bar"
[dependencies]
foo = "0.1.0"
"#)
- .file("src/lib.rs", "");
- p.build();
-
- t!(t!(File::create(p.root().join("Cargo.lock"))).write_all(br#"
+ .file("src/lib.rs", "")
+ .file("Cargo.lock", r#"
[root]
name = "bar"
version = "0.0.1"
[metadata]
"checksum foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "checksum"
-"#));
+"#);
+
+ p.build();
assert_that(p.cargo("build"),
execs().with_status(101).with_stderr("\
[dependencies]
foo = "0.1.0"
"#)
- .file("src/lib.rs", "");
- p.build();
-
- t!(t!(File::create(p.root().join("Cargo.lock"))).write_all(br#"
+ .file("src/lib.rs", "")
+ .file("Cargo.lock", r#"
[root]
name = "bar"
version = "0.0.1"
[metadata]
"checksum foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "<none>"
-"#));
+"#);
+ p.build();
assert_that(p.cargo("fetch"),
execs().with_status(101).with_stderr("\
[dependencies]
foo = {{ git = '{}' }}
"#, git.url()))
- .file("src/lib.rs", "");
- p.build();
-
- let lockfile = format!(r#"
+ .file("src/lib.rs", "")
+ .file("Cargo.lock", &format!(r#"
[root]
name = "bar"
version = "0.0.1"
[metadata]
"checksum foo 0.1.0 (git+{0})" = "checksum"
-"#, git.url());
- File::create(p.root().join("Cargo.lock")).unwrap()
- .write_all(lockfile.as_bytes()).unwrap();
+"#, git.url()));
+
+ p.build();
assert_that(p.cargo("fetch"),
execs().with_status(101).with_stderr("\
assert_that(p.cargo("build"), execs().with_status(0));
- let mut actual = String::new();
- File::open(p.root().join("Cargo.lock")).unwrap()
- .read_to_string(&mut actual).unwrap();
+ let actual = p.read_lockfile();
let expected = "\
[root]
fn lockfile_without_root() {
Package::new("foo", "0.1.0").publish();
- let p = project("bar")
- .file("Cargo.toml", r#"
- [package]
- name = "bar"
- version = "0.0.1"
- authors = []
-
- [dependencies]
- foo = "0.1.0"
- "#)
- .file("src/lib.rs", "");
- p.build();
-
let lockfile = r#"[[package]]
name = "bar"
version = "0.0.1"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
"#;
- File::create(p.root().join("Cargo.lock")).unwrap()
- .write_all(lockfile.as_bytes()).unwrap();
+
+ let p = project("bar")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "bar"
+ version = "0.0.1"
+ authors = []
+
+ [dependencies]
+ foo = "0.1.0"
+ "#)
+ .file("src/lib.rs", "")
+ .file("Cargo.lock", lockfile);
+
+ p.build();
assert_that(p.cargo("build"), execs().with_status(0));
- let mut lock = String::new();
- File::open(p.root().join("Cargo.lock")).unwrap()
- .read_to_string(&mut lock).unwrap();
+ let lock = p.read_lockfile();
assert!(lock.starts_with(lockfile.trim()));
}